// by Xeno
//#define __DEBUG__
#define THIS_FILE "d_init.sqf"
diag_log [diag_frameno, diag_ticktime, time, "Executing Dom d_init.sqf"];
#include "x_setup.sqf"
private ["_mname","_dtar","_ar","_pos","_nlocs","_nl","_name","_paramName","_h","_first_ar","_second_ar","_targets_list","_wbarracks","_D_AI_HUT","_standard_weap","_silenced","_glweaps","_basic","_machineg","_sniper","_atweap","_elem","_armor","_car","_ranover","_ww","_opfor_targets_ar","_blufor_targets_ar"];

// TYRGHEN - Because BIS Sucks
if (isNil QGVAR(hasParamsArray) || {!GVAR(hasParamsArray)}) then {
#include "x_paramshelper.sqf"
};

if (isServer) then {
	__ccppfln(x_shc\x_f\x_shcfunctions.sqf);
};

__ccppfln(x_common\x_f\x_netinit.sqf);

#include "i_common.sqf"

X_INIT = false;X_Server = isServer; X_Client = !isDedicated; X_JIP = false;X_SPE = false;X_MP = isMultiplayer;

#define __waitpl 0 spawn {scriptName "spawn_WaitForNotIsNullPlayer";waitUntil {!isNull player};X_INIT = true}
if (isServer) then {
	if (!isDedicated) then {
		X_SPE = true;
	};
	X_INIT = true;
} else {
	if (isNull player) then {
		X_JIP = true;
		__waitpl;
	} else {
		X_INIT = true;
	};
};

if (X_Client && {isMultiplayer}) then {
	0 spawn {
		scriptName "spawn_WaitForX_INIT";
		waitUntil {X_INIT};
		xr_phd_invulnerable = true;
		__pSetVar [QGVAR(p_ev_hd_last), time];
	};
};

if (isServer) then {
#include "i_server.sqf"
};

if (!isDedicated) then {
#include "i_client.sqf"
};

if (isDedicated) then {
	if (GVAR(WithRevive) == 0) then {
		__ccppfln(x_revive.sqf);
	};
};

[0, QGVAR(rep_ar), {_this setDamage 0;_this setFuel 1}] call FUNC(NetAddEvent);
[0, QGVAR(setcapt), {(_this select 0) setCaptive (_this select 1)}] call FUNC(NetAddEvent);
[0, QGVAR(say), {(_this select 0) say3D (_this select 1)}] call FUNC(NetAddEvent);
[0, QGVAR(nswm), {(_this select 0) switchMove (_this select 1)}] call FUNC(NetAddEvent);
[0, QGVAR(eswm), {_this switchMove ""}] call FUNC(NetAddEvent);
// TYRGHEN
[0, QGVAR(del_ruin), {_ruin = [["Ruins","Ruins_F"], _this, 10] call FUNC(NearestObjTypes);if (!isNull _ruin) then {deleteVehicle _ruin}}] call FUNC(NetAddEvent);

[QGVAR(lv2), {(_this select 0) lock (_this select 1)}] call FUNC(NetAddEventSTO);
[QGVAR(grpl), {(_this select 0) selectLeader (_this select 1)}] call FUNC(NetAddEventSTO);
[QGVAR(joing), {(_this select 1) join (_this select 0)}] call FUNC(NetAddEventSTO);
[0, QGVAR(r_delm), {deleteMarkerLocal _this}] call FUNC(NetAddEvent);
[QGVAR(grpslead), {(_this select 1) selectLeader (_this select 2)}] call FUNC(NetAddEventSTO);
[QGVAR(grpjoin), {[_this select 1] joinSilent (_this select 0)}] call FUNC(NetAddEventSTO);
[QGVAR(setFuel), {(_this select 0) setFuel (_this select 1)}] call FUNC(NetAddEventSTO);
[QGVAR(setvel0), {_this setVelocity [0,0,0]}] call FUNC(NetAddEventSTO);
[2, QGVAR(ppaws), {if (getPlayerUID player == _this) then {endMission "LOSER"}}] call FUNC(NetAddEvent);
[QGVAR(engineon), {(_this select 0) engineOn (_this select 1)}] call FUNC(NetAddEventSTO);
if (isServer) then {
	[QGVAR(hcunit), {
		if (isnil "HC_D_UNIT") then {
			HC_D_UNIT = _this;
			diag_log["HC UNIT SET",HC_D_UNIT];
		} else {
			diag_log["HC UNIT ALREADY SET",HC_D_UNIT,_this];
		};
	}] call FUNC(NetAddEventCTS);
	[QGVAR(hcready), {
		GVAR(HC_CLIENT_READY) = true; /*QGVAR(hcobj) call FUNC(NetRemoveEventCTS)*/
		__TRACE_1("HC READY","d_HC_CLIENT_READY");
	}] call FUNC(NetAddEventCTS);
	[1, QGVAR(m_box), {_this call FUNC(CreateDroppedBox)}] call FUNC(NetAddEvent);
	// TYRGHEN
	[1, QGVAR(air_box), {_this call FUNC(CreateDroppedBox)}] call FUNC(NetAddEvent);

	[QGVAR(p_group), {
		private "_idx";
		_idx = GVAR(player_groups) find (_this select 0);
		if (_idx == -1) then {
			GVAR(player_groups) set [count GVAR(player_groups), _this select 0];
			GVAR(player_groups_lead) set [count GVAR(player_groups_lead), _this select 1];
		} else {
			GVAR(player_groups_lead) set [_idx, _this select 1]
		};
	}] call FUNC(NetAddEventCTS);
	
	if (GVAR(domdatabase)) then {
		[QGVAR(ptkkg), {_this call FUNC(PAddTeamKillPoints)}] call FUNC(NetAddEventCTS);
		[QGVAR(reqps), {_this call FUNC(ServerGetPlayerStats)}] call FUNC(NetAddEventCTS);
	};
	
	[QGVAR(p_a), {_this call FUNC(GetPlayerStats)}] call FUNC(NetAddEventCTS);
	[QGVAR(air_taxi), {_this spawn FUNC(airtaxiserver)}] call FUNC(NetAddEventCTS);
	[1, QGVAR(r_box), {_this call FUNC(RemABox)}] call FUNC(NetAddEvent);
	[QGVAR(p_f_b_k), {_this call FUNC(KickPlayerBS)}] call FUNC(NetAddEventCTS);
	[QGVAR(p_bs), {_this call FUNC(RptMsgBS)}] call FUNC(NetAddEventCTS);
	[QGVAR(pas), {(_this select 0) addScore (_this select 1)}] call FUNC(NetAddEventCTS);
	[QGVAR(mrs_ch), {if (!isNull (_this select 0)) then {_this spawn FUNC(checktransport)}}] call FUNC(NetAddEventCTS);
	
	[QGVAR(hl_check), {
		_hl_check = GV(_this,GVAR(hl_check));
		if (isNil "_hl_check") then {
			_script = _this spawn {
				private ["_vec"];
				_vec = _this;
				while {true} do {
					if (isnil "_vec" || {isNull _vec}) exitWith {};
					_pos_v = position _vec;
					if (_pos_v select 2 < -20) exitWith {
						detach _vec;
						_pos_v set [2,0];
						_vec setVelocity [0,0,0];
						_vec setPos _pos_v;
						_vec setVelocity [0,0,0];
					};
					sleep 3;
				};
			};
			_this setVariable [QGVAR(hl_check), _script];
		} else {
			terminate _hl_check;
			_this setVariable [QGVAR(hl_check), nil];
		};
	}] call FUNC(NetAddEventCTS);
	
	[QGVAR(p_varn), {_this call FUNC(GetPlayerArray)}] call FUNC(NetAddEventCTS);
	[QGVAR(ad), {__addDead(_this)}] call FUNC(NetAddEventCTS);
	[QGVAR(ad2), {(_this select 0) setVariable [QGVAR(end_time), _this select 1];GVAR(allunits_add) set [count GVAR(allunits_add), _this select 0]}] call FUNC(NetAddEventCTS);
	[1, QGVAR(p_o_a), {
		_ar = GVAR(placed_objs_store) getVariable [_this select 0, []];
		if (count _ar > 0) then {_ar = _ar - [objNull]};
		_ar set [count _ar, _this select 1];
		GVAR(placed_objs_store) setVariable [_this select 0, _ar];
		((_this select 1) select 0) setVariable [QGVAR(owner), _this select 0];
		((_this select 1) select 0) addMPEventhandler ["MPKilled", {_this call FUNC(PlacedObjKilled)}];
	}] call FUNC(NetAddEvent);
	[1, QGVAR(p_o_r), {
		_ar = GVAR(placed_objs_store) getVariable [_this select 0, []];
		if (count _ar > 0) then {
			_ar = _ar - [objNull];
			if (count _ar > 0) then {
				{
					if ((_x select 1) == (_this select 1)) exitWith {_ar set [_forEachIndex, -1]};
				} forEach _ar;
				_ar = _ar - [-1];
			};
		};
		GVAR(placed_objs_store) setVariable [_this select 0, _ar]
	}] call FUNC(NetAddEvent);
	[QGVAR(p_o_a2), {
		_ar = GVAR(placed_objs_store2) getVariable [_this select 0, []];
		if (count _ar > 0) then {_ar = _ar - [objNull]};
		_ar set [count _ar, _this select 1];
		GVAR(placed_objs_store2) setVariable [_this select 0, _ar];
	}] call FUNC(NetAddEventCTS);
	
	[QGVAR(p_o_a2r), {
		_ar = GVAR(placed_objs_store2) getVariable [_this select 0, []];
		if (count _ar > 0) then {
			_ar = _ar - [_this select 0, objNull];
		};
		GVAR(placed_objs_store2) setVariable [_this select 0, _ar];
	}] call FUNC(NetAddEventCTS);
	
	[QGVAR(x_dr_t), {_this spawn FUNC(createdrop)}] call FUNC(NetAddEventCTS);
	[QGVAR(f_ru_i), {[_this] spawn FUNC(FacRebuild)}] call FUNC(NetAddEventCTS);
	[QGVAR(ari_type), {_this spawn FUNC(arifire)}] call FUNC(NetAddEventCTS);
	[QGVAR(l_v), {if !((_this select 0) in GVAR(wreck_cur_ar)) then {if (local (_this select 0)) then {(_this select 0) lock (_this select 1)} else {[QGVAR(lv2), _this] call FUNC(NetCallEventSTO)}}}] call FUNC(NetAddEventCTS);
	[1, QGVAR(mhqdepl), {if (local (_this select 0)) then {(_this select 0) lock (_this select 1)};if (_this select 1) then {(_this select 0) call FUNC(createMHQEnemyTeleTrig)} else {(_this select 0) call FUNC(removeMHQEnemyTeleTrig)}}] call FUNC(NetAddEvent);
	[QGVAR(g_p_inf), {_this call FUNC(GetAdminArray)}] call FUNC(NetAddEventCTS);
	[QGVAR(ad_deltk), {_this call FUNC(AdminDelTKs)}] call FUNC(NetAddEventCTS);
#ifdef __TT__
	[1, QGVAR(a_p_w), {GVAR(points_blufor) = GVAR(points_blufor) + _this}] call FUNC(NetAddEvent);
	[1, QGVAR(a_p_e), {GVAR(points_opfor) = GVAR(points_opfor) + _this}] call FUNC(NetAddEvent);
#endif
	[QGVAR(crl), {_this call FUNC(ChangeRLifes)}] call FUNC(NetAddEventCTS);
	[QGVAR(unit_tkr), {_this call FUNC(TKR)}] call FUNC(NetAddEventCTS);
	
	[QGVAR(PAIKP), {_this call FUNC(PAddAIKillPoints)}] call FUNC(NetAddEventCTS);
	[QGVAR(PACKP), {_this call FUNC(PAddCarKillPoints)}] call FUNC(NetAddEventCTS);
	if (GVAR(with_ai) && {GVAR(with_ranked)}) then {
		[QGVAR(AddKillAI), {_this call FUNC(AddKillsAI)}] call FUNC(NetAddEventCTS);
	};
	[QGVAR(kbmsg), {_this call FUNC(DoKBMsg)}] call FUNC(NetAddEventCTS);
	[QGVAR(sSetVar), {missionNamespace setVariable [_this select 0, _this select 1]}] call FUNC(NetAddEventCTS);
	[QGVAR(sm_var), {GVAR(sm_winner) = _this;GVAR(sm_resolved) = true;}] call FUNC(NetAddEventCTS);
	[QGVAR(sm_poi), {if (_this == 0) then {__INC(GVAR(sm_points_blufor))} else {__INC(GVAR(sm_points_opfor))}}] call FUNC(NetAddEventCTS);
	
	[QGVAR(smgetbonus), {
		__TRACE_1("smgetbonus","_this");
		GVAR(sm_winner) = _this select 0;
		GVAR(current_sm_bonus_vec) = _this select 1;
#ifdef __TT__
		switch (GVAR(sm_winner)) do {
			case 1: {GVAR(points_opfor) = GVAR(points_opfor) + (GVAR(tt_points) select 4)};
			case 2: {GVAR(points_blufor) = GVAR(points_blufor) + (GVAR(tt_points) select 4)};
		};	
#endif
		__TRACE("smgetbonus FUNC getbonus");
		0 spawn FUNC(getbonus);
	}] call FUNC(NetAddEventCTS);
#ifdef __TT__
	[QGVAR(addPoi), {_this call FUNC(AddPoints)}] call FUNC(NetAddEventCTS);
#endif
	[QGVAR(getSM), {0 spawn FUNC(getsidemission)}] call FUNC(NetAddEventCTS);
	[QGVAR(setgrps), {_this setVariable [QGVAR(fromHC), true]}] call FUNC(NetAddEventCTS);
	
	[QGVAR(nHCObj), {
		GVAR(HC_CLIENT_OBJ) = _this;
		diag_log ["HC_CLIENT_OBJ", _this];
	}] call FUNC(NetAddEventCTS);
	
	[QGVAR(crbike), {_this call FUNC(createPlayerBike)}] call FUNC(NetAddEventCTS);
	// TYRGHEN
	[QGVAR(ejectp), {diag_log format["EJECT: %1, %2 (%3)",(_this select 0),(_this select 1),getplayeruid(_this select 1)]; if (vehicle (_this select 0) != (_this select 0) && speed (vehicle (_this select 0)) < 1) then { (_this select 0) action ["eject", vehicle (_this select 0)]; };}] call FUNC(NetAddEventCTS);
	[QGVAR(docst), {_this spawn FUNC(createsecondary)}] call FUNC(NetAddEventCTS);
};

#include "x_missions\x_missionssetup.sqf"

if (X_SPE) then {GVAR(date_str) = date};

#ifndef __TT__
_nobs = nearestObjects [GVAR(FLAG_BASE), ["Land_Airport_Tower_F", "Land_MilOffices_V1_F","Land_Airport_right_F","Land_Airport_center_F","Land_Airport_left_F"], 70];
{
	_x allowDamage false;
} forEach _nobs;
#endif

if (isSteamMission) exitWith {endMission "LOSER"};

if (isServer) then {
	[QGVAR(mt_radio_down),true] call FUNC(NetSetJIP);
	[QUOTE(mt_radio_pos),[0,0,0]] call FUNC(NetSetJIP);
	[QUOTE(target_clear),false] call FUNC(NetSetJIP);
	[QUOTE(all_sm_res),false] call FUNC(NetSetJIP);
	[QGVAR(the_end),false] call FUNC(NetSetJIP);
	[QUOTE(ari_available),true] call FUNC(NetSetJIP);
	[QUOTE(ari2_available),true] call FUNC(NetSetJIP);
#ifndef __TT__
	[QGVAR(jet_s_reb),false] call FUNC(NetSetJIP);
	[QGVAR(chopper_s_reb),false] call FUNC(NetSetJIP);	
	[QGVAR(wreck_s_reb),false] call FUNC(NetSetJIP);
#endif
	[QGVAR(current_target_index),-1] call FUNC(NetSetJIP);
	[QGVAR(cur_sm_idx),-1] call FUNC(NetSetJIP);
	[QGVAR(num_ammo_boxes),0] call FUNC(NetSetJIP);
	[QUOTE(sec_kind),0] call FUNC(NetSetJIP);
	[QUOTE(resolved_targets),[]] call FUNC(NetSetJIP);
	[QUOTE(jump_flags),[]] call FUNC(NetSetJIP);
	[QGVAR(ammo_boxes),[]] call FUNC(NetSetJIP);
	[QGVAR(wreck_marker),[]] call FUNC(NetSetJIP);
	[QUOTE(para_available),true] call FUNC(NetSetJIP);
	[QGVAR(searchbody),objNull] call FUNC(NetSetJIP);
	[QGVAR(searchintel),[0,0,0,0,0,0,0]] call FUNC(NetSetJIP);
	
	//TYRGHEN
	[QGVAR(para_next_time),-1] call FUNC(NetSetJIP);
	[QGVAR(priority_position),[]] call FUNC(NetSetJIP);
	
	if (GVAR(with_ai) || {GVAR(with_ai_features) == 0}) then {
		[QGVAR(ari_blocked),false] call FUNC(NetSetJIP);
		[QGVAR(drop_blocked),false] call FUNC(NetSetJIP);
	};

#ifndef __TT__
	[QGVAR(campscaptured),0] call FUNC(NetSetJIP);
#else
	[QGVAR(campscaptured_w),0] call FUNC(NetSetJIP);
	[QGVAR(campscaptured_e),0] call FUNC(NetSetJIP);
#endif
	[QGVAR(currentcamps),[]] call FUNC(NetSetJIP);
	
	execVM "x_bikb\kbinit.sqf";
	
	GVAR(X_DropZone) = createVehicle [GVAR(HeliHEmpty), [0, 0, 0], [], 0, "NONE"];
	[QUOTE(X_DropZone), GVAR(X_DropZone)] call FUNC(NetSetJIP);
	
	GVAR(AriTarget) = createVehicle [GVAR(HeliHEmpty), [0, 0, 0], [], 0, "NONE"];
	[QGVAR(AriTarget),GVAR(AriTarget)] call FUNC(NetSetJIP);
	
	GVAR(AriTarget2) = createVehicle [GVAR(HeliHEmpty), [0, 0, 0], [], 0, "NONE"];
	[QGVAR(AriTarget2),GVAR(AriTarget2)] call FUNC(NetSetJIP);
	
	[QGVAR(farps), []] call FUNC(NetSetJIP);
	
#ifdef __TT__
	GVAR(points_blufor) = 0;
	GVAR(points_opfor) = 0;
	GVAR(kill_points_blufor) = 0;
	GVAR(kill_points_opfor) = 0;
	[QUOTE(points_array),[0,0,0,0]] call FUNC(NetSetJIP);
#endif
	
	__ccppfln(x_server\x_initx.sqf);
	
	if (GVAR(weather) == 0 && {GVAR(FastTime) == 0}) then {
		execFSM "fsms\WeatherServer.fsm";
	};

	__TRACE_1(QGVAR(ISLAND_TARGETS_PRIORITY_TOWNS),QGVAR(ISLAND_TARGETS_PRIORITY_TOWNS))
	// create random list of targets
#ifndef __DEFAULT__
	GVAR(maintargets_list) = call FUNC(createrandomtargets);
#else
	if (GVAR(number_targets_h) < 50) then {
		GVAR(maintargets_list) = call FUNC(createrandomtargets);
		//GVAR(maintargets_list) = [0,1,2,3];
	} else {
		// TODO: make routes for ATLIS
		switch (GVAR(number_targets_h)) do {
			case 50: {GVAR(maintargets_list) = GVAR(ISLAND_TARGETS_WEST_ROUTE)};
			case 60: {GVAR(maintargets_list) = GVAR(ISLAND_TARGETS_NORTH_ROUTE)};
			case 70: {GVAR(maintargets_list) = GVAR(ISLAND_TARGETS_EAST_ROUTE)};
			case 90: {GVAR(maintargets_list) = GVAR(ISLAND_TARGETS_ORDERED_ROUTE)};
		};
	};
#endif
	__TRACE_1(QGVAR(maintargets_list),QGVAR(maintargets_list))
	__TRACE_1(QGVAR(MainTargetStart),QGVAR(MainTargetStart))
	// TYRGHEN - Added the ability to choose the starting city
	if (GVAR(MainTargetStart) >= 0 && GVAR(number_targets_h) < 50) then {
		private "_town_id";
		_town_id = GVAR(ISLAND_TARGETS_PRIORITY_TOWNS) select GVAR(MainTargetStart);
		__TRACE_1("_town_id",_town_id)
		if (_town_id in GVAR(maintargets_list)) then {
			GVAR(maintargets_list) = GVAR(maintargets_list) - [_town_id];
		} else {
			GVAR(maintargets_list) set [(count GVAR(maintargets_list)) - 1, -1];
			GVAR(maintargets_list) = GVAR(maintargets_list) - [-1];
		};
		GVAR(maintargets_list) = [[_town_id], GVAR(maintargets_list)]  call FUNC(arraypushstack2);
		__TRACE_1(QGVAR(maintargets_list),QGVAR(maintargets_list))
	};

	// create random list of side missions
	// TYRGHEN - Added IsMutiplayer Check
	if (GVAR(random_sm_array) && isMultiplayer) then {
		GVAR(side_missions_random) = GVAR(sm_array) call FUNC(RandomArray);
	} else {
		GVAR(side_missions_random) = GVAR(sm_array);
	};
	
	__TRACE_1("","d_side_missions_random")
	
	GVAR(current_counter) = 0;
	GVAR(current_mission_counter) = 0;

#ifndef __TT__
	// TYRGHEN
	// Add a true as 5th param to make it team reserved
	
	// editor varname, unique number, true = respawn only when the chopper is completely destroyed, false = respawn after some time when no crew is in the chopper or chopper is destroyed
	// unique number must be between 3000 and 3999
	// array:
	// - var name
	// - unique id
	// - respawn only when destroyed
	// - respawn after seconds, if not respawn only when destroyed
	// - reserved to MSO
	// - respawn delay when destroyed
	[
		[ch1,3001,false,600],[ch2,3002,false,600],[ch3,3003,false,600],[ch4,3004,false,600],[ch5,3005,false,600],[ch6,3006,false,600],
		[vch1,3007,false,4200,true,100],[vch2,3008,false,4200,true,100],[vch3,3009,false,4200,true]
	] execVM "x_server\x_helirespawn2.sqf";

	// TYRGHEN
	// Add a true as 4th param to make it team reserved
	
	// editor varname, unique number
	//0-99 = MHQ, 100-199 = Medic vehicles, 200-299 = Fuel, Repair, Reammo trucks, 300-399 = Engineer Salvage trucks, 400-499 = Transport trucks
	[
		[xmhq1,0],[xmhq2,1],[xmedvec,100],[xvec3,200],[xvec4,201],[xvec5,202], [xvec7,203],
		[xvec8,204], [xvec9,205], [xvec6,300], [xvec10,301],
		[vhu1,400,0,true], [vhu2,401,0,true],
		[xamv1,404], [xamv2,405],[xtr1,406], [xtr2,407],
		[xmed,412], [xfuel,413],[xammo,414], [xrep,415],
		[xor1,416], [xor2,417]
	] execVM "x_server\x_vrespawn2.sqf";
#else
	// editor varname, unique number, true = respawn only when the chopper is completely destroyed, false = respawn after some time when no crew is in the chopper or chopper is destroyed
	// unique number must be between 3000 and 3999 for blufor and 4000-4999 for opfor
	[
		[ch1,3001,true],[ch2,3002,true],[ch3,3003,false],[ch4,3004,false],[ch5,3005,false,600],[ch6,3006,false,600],
		[chR1,4001,true],[chR2,4002,true],[chR3,4003,false],[chR4,4004,false],[chR5,4005,false,600],[chR6,4006,false,600]
	] execVM "x_server\x_helirespawn2.sqf";		

	// editor varname, unique number
	//blufor
	//0-99 = MHQ, 100-199 = Medic vehicles, 200-299 = Fuel, Repair, Reammo trucks, 300-399 = Engineer Salvage trucks, 400-499 = Transport trucks
	//opfor
	//1000-1099 = MHQ, 1100-1199 = Medic vehicles, 1200-1299 = Fuel, Repair, Reammo trucks, 1300-1399 = Engineer Salvage trucks, 1400-1499 = Transport trucks
	[
		[xvec1,0],[xvec2,1],[xmedvec,100],[xvec3,200],[xvec4,201],[xvec5,202],[xvec6,300],[xvec7,400],
		[xvecR1,1000],[xvecR2,1001],[xmedvecR,1100],[xvecR3,1200],[xvecR4,1201],[xvecR5,1202],[xvecR6,1300],[xvecR7,1400]
	] execVM "x_server\x_vrespawn2.sqf";
#endif
	if (!isNil QGVAR(boat_1)) then {
		execFSM "fsms\Boatrespawn.fsm";
	};
	if (!isNil QGVAR(wreck_rep)) then {
		[GVAR(wreck_rep),(localize "STR_DOM_MISSIONSTRING_0"),GVAR(heli_wreck_lift_types)] execFSM "fsms\RepWreck.fsm";
	};
#ifdef __TT__
	if (!isNil QGVAR(wreck_rep2)) then {
		[GVAR(wreck_rep2),(localize "STR_DOM_MISSIONSTRING_0"),GVAR(heli_wreck_lift_types)] execFSM "fsms\RepWreck.fsm";
	};
	GVAR(public_points) = true;
#endif
	GVAR(check_boxes) = [];
	__ccppfln(x_server\x_setupserver.sqf);
	if (GVAR(MissionType) != 2) then {
		8 spawn FUNC(createnexttarget);
	};
	
	if (GVAR(with_ai)) then {
		GVAR(player_groups) = [];
		GVAR(player_groups_lead) = [];
	};
	if (GVAR(FastTime) > 0) then {
		execFSM "fsms\FastTime.fsm";
	};
	
	["DOM_ID", "onPlayerConnected", {[_id,_name,_uid] call FUNC(serveropc);}] call BFUNC(addStackedEventHandler);
	["DOM_ID", "onPlayerDisconnected", {[_id,_name,_uid] call FUNC(serveropd);}] call BFUNC(addStackedEventHandler);
};

QGVAR(island_marker) setMarkerAlphaLocal 0;

if (!isDedicated) then {
#ifndef __TT__
	if (! isNil QGVAR(wreck_service)) then {[QGVAR(wreck_service), getPosASL GVAR(wreck_rep),"ICON","ColorYellow",[1,1],(localize "STR_DOM_MISSIONSTRING_1"),0,"n_service"] call FUNC(CreateMarkerLocal);};
	if (! isNil QGVAR(aircraft_service)) then {[QGVAR(aircraft_service), getPosASL GVAR(jet_trigger),"ICON","ColorYellow",[1,1],(localize "STR_DOM_MISSIONSTRING_2"),0,"n_service"] call FUNC(CreateMarkerLocal);};
	if (! isNil QGVAR(chopper_service)) then {[QGVAR(chopper_service), getPosASL GVAR(chopper_trigger),"ICON","ColorYellow",[1,1],(localize "STR_DOM_MISSIONSTRING_3"),0,"n_service"] call FUNC(CreateMarkerLocal);};
	if (! isNil QGVAR(vehicle_service)) then {[QGVAR(vehicle_service), getPosASL GVAR(vecre_trigger),"ICON","ColorYellow",[1,1],(localize "STR_DOM_MISSIONSTRING_4"),0,"n_service"] call FUNC(CreateMarkerLocal);};
	["Ammobox Reload", getPosASL GVAR(AMMOLOAD),"ICON","ColorYellow",[1,1],(localize "STR_DOM_MISSIONSTRING_5"),0,"hd_dot"] call FUNC(CreateMarkerLocal);
	[QGVAR(teleporter), getPosASL GVAR(FLAG_BASE),"ICON","ColorYellow",[1,1],(localize "STR_DOM_MISSIONSTRING_6"),0,"mil_flag"] call FUNC(CreateMarkerLocal);
#else
	if (! isNil QGVAR(wreck_service)) then {[QGVAR(wreck_service), getPosASL GVAR(wreck_rep),"ICON","ColorYellow",[1,1],(localize "STR_DOM_MISSIONSTRING_1"),0,"n_service"] call FUNC(CreateMarkerLocal);};
	if (! isNil QGVAR(aircraft_service)) then {[QGVAR(aircraft_service), getPosASL GVAR(jet_trigger),"ICON","ColorYellow",[1,1],(localize "STR_DOM_MISSIONSTRING_2"),0,"n_service"] call FUNC(CreateMarkerLocal);};
	if (! isNil QGVAR(chopper_service)) then {[QGVAR(chopper_service), getPosASL GVAR(chopper_trigger),"ICON","ColorYellow",[1,1],(localize "STR_DOM_MISSIONSTRING_3"),0,"n_service"] call FUNC(CreateMarkerLocal);};
	if (! isNil QGVAR(vehicle_service)) then {[QGVAR(vehicle_service), getPosASL GVAR(vecre_trigger),"ICON","ColorYellow",[1,1],(localize "STR_DOM_MISSIONSTRING_4"),0,"n_service"] call FUNC(CreateMarkerLocal);};
	["Ammobox Reload", getPosASL GVAR(AMMOLOAD),"ICON","ColorYellow",[1,1],(localize "STR_DOM_MISSIONSTRING_5"),0,"hd_dot"] call FUNC(CreateMarkerLocal);
	[QGVAR(teleporter), getPosASL GVAR(WFLAG_BASE),"ICON","ColorYellow",[1,1],(localize "STR_DOM_MISSIONSTRING_6"),0,"mil_flag"] call FUNC(CreateMarkerLocal);
	
	if (! isNil QGVAR(wreck_serviceR)) then {[QGVAR(wreck_serviceR), getPosASL GVAR(wreck_rep2),"ICON","ColorYellow",[1,1],(localize "STR_DOM_MISSIONSTRING_1"),0,"n_service"] call FUNC(CreateMarkerLocal);};
	if (! isNil QGVAR(aircraft_serviceR)) then {[QGVAR(aircraft_serviceR), getPosASL GVAR(jet_trigger2),"ICON","ColorYellow",[1,1],(localize "STR_DOM_MISSIONSTRING_2"),0,"n_service"] call FUNC(CreateMarkerLocal);};
	if (! isNil QGVAR(chopper_serviceR)) then {[QGVAR(chopper_serviceR), getPosASL GVAR(chopper_triggerR),"ICON","ColorYellow",[1,1],(localize "STR_DOM_MISSIONSTRING_3"),0,"n_service"] call FUNC(CreateMarkerLocal);};
	if (! isNil QGVAR(vehicle_serviceR)) then {[QGVAR(vehicle_serviceR), getPosASL GVAR(vecre_trigger2),"ICON","ColorYellow",[1,1],(localize "STR_DOM_MISSIONSTRING_4"),0,"n_service"] call FUNC(CreateMarkerLocal);};
	["Ammobox ReloadR", getPosASL GVAR(AMMOLOAD2),"ICON","ColorYellow",[1,1],(localize "STR_DOM_MISSIONSTRING_5"),0,"hd_dot"] call FUNC(CreateMarkerLocal);
	[QGVAR(teleporter_1), getPosASL GVAR(EFLAG_BASE),"ICON","ColorYellow",[1,1],(localize "STR_DOM_MISSIONSTRING_6"),0,"mil_flag"] call FUNC(CreateMarkerLocal);
#endif
};

#ifdef __TT__
{
	_x setMarkerAlphaLocal 0;
} forEach [QGVAR(chopper_service),QGVAR(wreck_service),QGVAR(teleporter),QGVAR(aircraft_service),"bonus_air","bonus_vehicles","Ammobox Reload",QGVAR(vehicle_service),
	"Start",QGVAR(chopper_serviceR),QGVAR(wreck_serviceR),QGVAR(teleporter_1),QGVAR(aircraft_serviceR),"bonus_airR","bonus_vehiclesR","Ammobox ReloadR","Start_opfor",QGVAR(vehicle_serviceR)];
#endif

GVAR(init_processed) = true;

if (!isMultiplayer && {!isDedicated}) then {
	GVAR(player_stuff) = [GVAR(AutoKickTime), time, "", 0, str(player), sideUnknown, name player, 0, xr_max_lives, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
	GVAR(player_store) setVariable ["", GVAR(player_stuff)];
};

0 spawn FUNC(disdeadvec);

#include "x_commoncustomcode.sqf";

diag_log [diag_frameno, diag_ticktime, time, "Dom d_init.sqf processed"];
